package com.woniuxy.boot.nb_feedback.controller.app;

import com.woniuxy.boot.common.pojo.ResponseResult;
import com.woniuxy.boot.common.util.JwtUtil;
import com.woniuxy.boot.nb_feedback.bean.Feedback;
import com.woniuxy.boot.nb_feedback.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("app/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    /**
     * 用户增加反馈接口
     **/
    @PostMapping("addFeedback")
    public ResponseResult<Void> addFeedback(@RequestBody Feedback feedback, @RequestHeader("token") String token) {
        feedback.setUserId(JwtUtil.parseJwt(token));
        feedbackService.addFeedback(feedback);
        return ResponseResult.SUCCESS;
    }

    /**
     * 用户根据自己的用户id查询自己所有的反馈接口
     **/
    @GetMapping("getFeedbackById")
    public ResponseResult<List<Feedback>> getFeedbackById(@RequestHeader("token") String token) {
        return new ResponseResult<>(feedbackService.getFeedbackById(JwtUtil.parseJwt(token)));
    }

}
